From 4297249197a5adf2c7517f6d55ed4273ce5e8a05 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 25 Jul 2011 16:42:53 +0100 Subject: [PATCH] x86-64/MMCFG: finally make Fam10 enabling work Forcibly enabling the MMCFG space on AMD Fam10 CPUs cannot be expected to work since with the firmware not being aware of the address range used it cannot possibly reserve the space in E820 or ACPI resources. Hence we need to manually insert the range into the E820 table, and enable the range only when the insertion actually works without conflict. Further, the actual enabling of the space is done from identify_cpu(), which means that acpi_mmcfg_init() muts be called after that function (and hance should not be called from acpi_boot_init()). Otherwise, Dom0 would be able to use MMCFG, but Xen wouldn't. Signed-off-by: Jan Beulich --- xen/arch/x86/acpi/boot.c | 2 -- xen/arch/x86/e820.c | 49 +++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 2 ++ xen/arch/x86/x86_32/pci.c | 5 --- xen/arch/x86/x86_64/mmconf-fam10h.c | 4 ++- xen/include/asm-x86/e820.h | 2 ++ 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/acpi/boot.c b/xen/arch/x86/acpi/boot.c index f6309a6e92..6262dac9d9 100644 --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -832,8 +832,6 @@ int __init acpi_boot_init(void) acpi_dmar_init(); - acpi_mmcfg_init(); - erst_init(); return 0; diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index a29a153c54..1697e770c2 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -563,6 +563,55 @@ static void __init machine_specific_memory_setup( clip_to_limit(top_of_ram, "MTRRs do not cover all of memory."); } +/* This function relies on the passed in e820->map[] being sorted. */ +int __init e820_add_range( + struct e820map *e820, uint64_t s, uint64_t e, uint32_t type) +{ + unsigned int i; + + for ( i = 0; i < e820->nr_map; ++i ) + { + uint64_t rs = e820->map[i].addr; + uint64_t re = rs + e820->map[i].size; + + if ( rs == e && e820->map[i].type == type ) + { + e820->map[i].addr = s; + return 1; + } + + if ( re == s && e820->map[i].type == type && + (i + 1 == e820->nr_map || e820->map[i + 1].addr >= e) ) + { + e820->map[i].size += e - s; + return 1; + } + + if ( rs >= e ) + break; + + if ( re > s ) + return 0; + } + + if ( e820->nr_map >= ARRAY_SIZE(e820->map) ) + { + printk(XENLOG_WARNING "E820: overflow while adding region" + " %"PRIx64"-%"PRIx64"\n", s, e); + return 0; + } + + memmove(e820->map + i + 1, e820->map + i, + (e820->nr_map - i) * sizeof(*e820->map)); + + e820->nr_map++; + e820->map[i].addr = s; + e820->map[i].size = e - s; + e820->map[i].type = type; + + return 1; +} + int __init e820_change_range_type( struct e820map *e820, uint64_t s, uint64_t e, uint32_t orig_type, uint32_t new_type) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index c2a2aaab56..83d59025d1 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1248,6 +1248,8 @@ void __init __start_xen(unsigned long mbi_p) #ifdef CONFIG_X86_64 vesa_mtrr_init(); + + acpi_mmcfg_init(); #endif if ( opt_nosmp ) diff --git a/xen/arch/x86/x86_32/pci.c b/xen/arch/x86/x86_32/pci.c index 1f77ebc835..6bc61185c3 100644 --- a/xen/arch/x86/x86_32/pci.c +++ b/xen/arch/x86/x86_32/pci.c @@ -60,8 +60,3 @@ int pci_find_ext_capability(int seg, int bus, int devfn, int cap) { return 0; } - -void acpi_mmcfg_init(void) -{ - return; -} diff --git a/xen/arch/x86/x86_64/mmconf-fam10h.c b/xen/arch/x86/x86_64/mmconf-fam10h.c index d8c29ba72b..bd06f2b0cd 100644 --- a/xen/arch/x86/x86_64/mmconf-fam10h.c +++ b/xen/arch/x86/x86_64/mmconf-fam10h.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -131,7 +132,8 @@ static void __init get_fam10h_pci_mmconf_base(void) return; out: - fam10h_pci_mmconf_base = start; + if (e820_add_range(&e820, start, start + SIZE, E820_RESERVED)) + fam10h_pci_mmconf_base = start; } void __cpuinit fam10h_check_enable_mmcfg(void) diff --git a/xen/include/asm-x86/e820.h b/xen/include/asm-x86/e820.h index d0486ae7c5..0fd81f6a0f 100644 --- a/xen/include/asm-x86/e820.h +++ b/xen/include/asm-x86/e820.h @@ -28,6 +28,8 @@ extern int reserve_e820_ram(struct e820map *e820, uint64_t s, uint64_t e); extern int e820_change_range_type( struct e820map *e820, uint64_t s, uint64_t e, uint32_t orig_type, uint32_t new_type); +extern int e820_add_range( + struct e820map *, uint64_t s, uint64_t e, uint32_t type); extern unsigned long init_e820(const char *, struct e820entry *, int *); extern struct e820map e820; -- 2.30.2